package myDictionary1;

import myDictionary.MyDictionary;

import java.util.Scanner;

public class MyDictionary1test {
    private static Scanner sc=new Scanner(System.in);
    private static MyDictionary1Dao dao=new MyDictionary1DaoIO();
    public static void main(String[] args) {

        while (true) {
            System.out.println("----欢迎光临----=");
            System.out.println("1.注册");
            System.out.println("2.登陆");
            System.out.println("3.查询所有用户");
            System.out.println("4.删除");
            System.out.println("5.退出");
            System.out.println("请输入你的选择：");

            String num=sc.nextLine();
            switch (num){
                case "1":
                   saveFace();
                    break;
                case "2":
                    queryFace();
                    break;
                case "3":
                    queryAllFace();
                    break;
                case "4":
                    deleteFace();
                    break;
                case "5":
                    System.out.println("欢迎下次光临");
                    System.exit(0);
                    break;
                default:
                    System.out.println("输入有误");
            }
        }
    }

    private static void deleteFace() {
        System.out.println("-----删除界面-----");
        System.out.println("请输入要删除的中文或英文");
        String name=sc.nextLine();
        dao.delete(name);
    }

    private static void queryAllFace() {
        System.out.println("----查询所有界面----");
        dao.queryAll();
    }

    private static void queryFace() {
        System.out.println("----查询界面----");
        System.out.println("请输入英或中：");
        String name=sc.nextLine();
        MyDictionary d=dao.query(name);
        if (d==null){
            System.out.println("词典没有该单词,还需要升级");
        }else{
            System.out.println(d);
        }
    }

    private static void saveFace() {
        System.out.println("----保存界面----");
        System.out.println("请输入id");
        String ids=sc.nextLine();

        int id=Integer.parseInt(ids);
        System.out.println("请输入英文：");
        String english=sc.nextLine();
        System.out.println("请输入中文");
        String chinese=sc.nextLine();
        System.out.println("请输入备注：");
        String comments=sc.nextLine();

        MyDictionary1 d=new MyDictionary1(id,english,chinese,comments);
        dao.sava(d);
    }


}
